<template>
  <div class="app-container">
    <div class="filter-container">
      <el-form ref="dataForm" size="mini" :model="listQuery" label-position="right" label-width="auto">
        <div class="lineBox">
          <el-form-item label="实体类型：" prop="type">
            <el-select v-model="listQuery.entity_type">
              <el-option label="全部" value="0" />
              <el-option label="头实体" value="1" />
              <el-option label="尾实体" value="2" />
            </el-select>
          </el-form-item>
        </div>
        <div class="lineBox">
          <el-form-item label="分离结果：" prop="type">
            <el-select v-model="listQuery.fl" :clearable="true">
              <el-option label="有结果" value="1" />
              <el-option label="空结果" value="2" />
            </el-select>
          </el-form-item>
        </div>
        <div class="lineBox">
          <el-form-item label="实体名称：" prop="entity_name">
            <el-input v-model="listQuery.entity_name" size="mini" placeholder="" style="width: 180px;" />
          </el-form-item>
        </div>

        <div class="lineBox">
          <el-form-item label="原始字符" prop="original_char">
            <el-input v-model="listQuery.original_char" size="mini" placeholder="" style="width: 180px;" />
          </el-form-item>
        </div>

        <div class="lineBox">
          <el-form-item label="分离后的字符" prop="separate_after">
            <el-input v-model="listQuery.separate_after" size="mini" placeholder="" style="width: 180px;" />
          </el-form-item>
        </div>

        <div class="lineBox">
          <el-button size="mini" type="primary" icon="el-icon-search" @click="handleFilter">
            查询
          </el-button>
        </div>
      </el-form>
    </div>

    <div class="myTable" style="min-height: 600px;">
      <el-table :key="tableKey" :data="list" fit size="mini" highlight-current-row style="width: 100%;">
        <el-table-column label="ID" prop="id" align="center" width="50" />
        <el-table-column label="分离任务ID" prop="task_dic" align="center" min-width="80" />
        <el-table-column label="档案ID" prop="article_id" align="center" min-width="80" />

        <el-table-column label="三元组ID" prop="triplet_id" align="center" min-width="100" />
        <el-table-column label="实体类型" prop="entity_type" align="center" min-width="100" />
        <el-table-column label="实体名称" prop="entity_name" align="center" min-width="100" />
        <el-table-column label="原始字符串" prop="original_char" align="center" min-width="100" />
        <el-table-column label="A字典" prop="separate_first" align="center" min-width="100" />
        <el-table-column label="B字典" prop="separate_after" align="center" min-width="100" />
        <el-table-column label="提取时间" prop="create_time" align="center" min-width="100" />
      </el-table>
    </div>
    <pagination size="mini" :page-sizes="[10]" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit"
      layout="total, sizes, prev, pager, next, jumper" @pagination="getList" />
    <addNoticeDlg ref="addNoticeDlg" @getList="getList" />
  </div>
</template>

<script>
import { stringsegApi } from '@/api/stringseg'
import Pagination from '@/components/Pagination' // secondary package based on el-pagination

export default {

  components: { Pagination },

  data() {
    return {

      formInline: {
        user: "",
        region: ""
      },
      value: '',

      tableKey: 0,
      list: [],
      total: 0,
      listLoading: false,
      listQuery: {
        pageNumber: 1,
        page: 1,
        limit: 10,
        entity_type: "0",
        entity_name: "",
        original_char: "",
        separate_after: "",
        task_dic: null, // 
        fl: null, //


      },


    }
  },



  created() {



    if (this.$route.query.id) {
      this.listQuery.task_dic = this.$route.query.id
    }

    this.getList()
  },
  methods: {

    handleFilter() {
      this.listQuery.page = 1
      this.getList()
    },

    // 数据列表
    async getList() {
      this.listLoading = true
      const response = await stringsegApi("getStringsegList", this.listQuery)
      if (response.code == 200) {
        this.list = response.data.resultList
        this.total = response.totalCount
        // this.type = response.type
        //   // Just to simulate the time of the request
        setTimeout(() => {
          this.listLoading = false
        }, 1.5 * 1000)
      }
    },
    handleUpdate(row) {
      this.$refs.addNoticeDlg.showDialog(row)
    },
    handleCreate() {
      this.$refs.addNoticeDlg.showDialog()
    },

    // 删除指标
    async handleDelete(row, index) {
      this.$confirm('此操作将永久删除该记录, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(async () => {
        const data = { 'id': row.id }

        const response = await dictionaryApi("delDictionaryById", data)
        if (response.code == 200) {
          this.$notify({
            title: '成功',
            message: response.message,
            type: 'success',
            duration: 2000
          })
          this.list.splice(index, 1)
        } else {
          this.$notify({
            title: '失败',
            message: response.message,
            type: 'error',
            duration: 2000
          })
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },

    // 修改跳转
    async skip(row, index) {

      this.$router.push('/template/save?id=' + row.id)

    }
  }
}
</script>

<style lang="scss" scoped>
.demo-image__preview {
  float: left;
  margin-left: 5px;
}
.demonstration {
  font-size: 12px;
  color: #333;
  font-weight: normal;
}
</style>
